<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>圆的周长和面积</title>
	</head>
	<body>
		<p>圆的半径:</p>
		<input id="n1" type="text"/>
		<br />
		<br />
		<input id="btn" type="button" value="求圆的周长"  onclick="c()"/>
		<input id="btn" type="button" value="求圆的面积"  onclick="s()"/>
		<p id="r"></p>
		<script>
			function c(){
			var num1=document.getElementById('n1');//boject
			var r=document.getElementById('r');
			//num1.value,代表内容（String),trim()表示去除string的前后空格
			if(!Boolean(num1.value.trim())){
				alert("你还未输入")
				return
			}
			if(isNaN(num1.value)){
				alert("输入不合法，非数字型");
				return
				}else{
				  	r.innerHTML=Number(num1.value)*2*3.14
				}
			}
			function s(){
			var num1=document.getElementById('n1');
			var r=document.getElementById('r');
			var result1=num1.value*num1.value*3.14;
			if(isNaN(num1.value)){
				alert("圆的半径不合法,重新输入.");
				  }else{		
				  	r.innerHTML="圆的面积是"+parseInt(result1);
				  }
				  	}
		</script>
	</body>
</html>
